/*
 * MSIGraphXView.java
 */
package msigraphx;

import com.mxgraph.model.mxCell;
import com.mxgraph.swing.handler.mxVertexHandler;
import java.awt.event.KeyEvent;
import java.util.Collection;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import com.sun.corba.se.impl.orbutil.graph.Graph;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.io.*;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.filechooser.*;

/**
 * The application's main frame.
 */
public class MSIGraphXView extends FrameView {

    public MSIGraphXView(SingleFrameApplication app) {
        super(app);

        initComponents();
        initMyComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    private void initMyComponents() {
        enableButtons(false);

    }
//    Object ala;
//    mxGraph graph;

    public void selectButtons(boolean value) {

        computeButton.setSelected(value);
        addEdgeToggleButton.setSelected(value);
        addVertexToggleButton.setSelected(value);
        selectKnownButton.setSelected(value);
        selectSoughtButton.setSelected(value);
    }

    public void enableButtons(boolean value) {

        computeButton.setEnabled(value);
        addEdgeToggleButton.setEnabled(value);
        addVertexToggleButton.setEnabled(value);
        selectKnownButton.setEnabled(value);
        selectSoughtButton.setEnabled(value);
        closeTabButton.setEnabled(value);
        nameTextField.setEnabled(value);
    }

    @Action
    public mxGraph addGraph() {
        enableButtons(true);

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();
        final mxGraphComponent graphComponent = new mxGraphComponent(graph);
        tabs.add(new Integer(tabs.getTabCount()).toString(), graphComponent);
        setGraphListener(graphComponent);

        tabs.setSelectedIndex(tabs.getTabCount() - 1);
        return graph;
    }

    public void setGraphListener(final mxGraphComponent graphComponent) {
        final mxGraph graph = graphComponent.getGraph();
        graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {

            public void mouseReleased(MouseEvent e) {
                mxCell cell = (mxCell) graphComponent.getCellAt(e.getX(), e.getY());
                if (cell != null) {
                    if (addEdgeToggleButton.isSelected() && cell.isVertex()) {
                        addEdge(cell);
                    } else if (selectKnownButton.isSelected()) {
                        if (cell.isVertex()) {
                            graph.getModel().beginUpdate();
                            try {
                                if (cell.getStyle() != null && cell.getStyle().contains("fillColor=green")) {
                                    cell.setStyle("");
                                } else {
                                    cell.setStyle("fillColor=green");
                                }
                            } finally {
                                graph.getModel().endUpdate();
                                graph.refresh();
                            }
                        }
                    } else if (selectSoughtButton.isSelected()) {
                        if (cell.isVertex()) {
                            graph.getModel().beginUpdate();
                            try {
                                if (cell.getStyle() != null && cell.getStyle().contains("fillColor=red")) {
                                    cell.setStyle("");
                                } else {
                                    cell.setStyle("fillColor=red");
                                    selectButtons(false);
                                }
                            } finally {
                                graph.getModel().endUpdate();
                                graph.refresh();
                                selectSoughtButton.setSelected(false);
                            }
                        }
                    } else {
                        editProperty(cell);
                    }
                } else if (addVertexToggleButton.isSelected()) {
                    addVertex(e.getX(), e.getY(), nameTextField.getText());
                }
            }
        });

        graphComponent.getGraphControl().addKeyListener(new KeyListener() {

            public void keyTyped(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                    activeGraph.removeSelectionCell(activeGraph.getSelectionCell());
                }
                System.out.print("delete\n");
            }

            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                    activeGraph.removeSelectionCell(activeGraph.getSelectionCell());
                }
                System.out.print("delete\n");
            }

            public void keyReleased(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                    activeGraph.removeSelectionCell(activeGraph.getSelectionCell());
                }
                System.out.print("delete\n");
            }
        });
    }

    /**
     * @return the activeGraph
     */
    public mxGraph getActiveGraph() {
        setActiveGraph(((mxGraphComponent) tabs.getSelectedComponent()).getGraph());
        return activeGraph;
    }

    /**
     * @param activeGraph the activeGraph to set
     */
    public void setActiveGraph(mxGraph activeGraph) {
        tabs.setSelectedComponent((mxGraphComponent) activeGraph.getDefaultParent());
        this.activeGraph = activeGraph;
    }

    private class AddGraphTask extends org.jdesktop.application.Task<Object, Void> {

        AddGraphTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to AddGraphTask fields, here.
            super(app);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
        }
    }

    public void addVertex(int x, int y, String label) {
        mxGraphComponent gc = (mxGraphComponent) tabs.getSelectedComponent();
        Object c = gc.getGraph().getSelectionCell();
        mxGraph graph = gc.getGraph();

        graph.getModel().beginUpdate();
        try {
            graph.insertVertex(
                    graph.getDefaultParent(), null, "Vertex", x, y, 80, 30);
//            addVertexToggleButton.setSelected(false);
        } finally {
            graph.getModel().endUpdate();
        }
    }

    public void removeVertex() {
    }

    public mxCell addEdge(mxCell vertex) {
        if (addFirstVertexEdge == null) {
            addFirstVertexEdge = vertex;
            return null;
        } else {
            mxGraphComponent gc = (mxGraphComponent) tabs.getSelectedComponent();
            Object c = gc.getGraph().getSelectionCell();
            mxGraph graph = gc.getGraph();

            Object parent = graph.getDefaultParent();
            mxCell edge = null;
            graph.getModel().beginUpdate();
            try {
                edge = (mxCell) graph.insertEdge(parent, null, "0", addFirstVertexEdge, vertex);
                addFirstVertexEdge = null;
//                addEdgeToggleButton.setSelected(false);
            } finally {
                graph.getModel().endUpdate();
            }
            return edge;
        }
    }

    public void removeEdge() {
    }

    public void editProperty(String property) {

        mxGraphComponent gc = (mxGraphComponent) tabs.getSelectedComponent();
        Object selectionObject = gc.getGraph().getSelectionCell();
        mxGraph graph = gc.getGraph();
        mxCell selectionCell = (mxCell) selectionObject;

        if (selectionCell != null) {
            selectionCell.setValue(property);
            graph.refresh();
        }
    }

    public void editProperty(mxCell cell) {
        mxGraphComponent gc = (mxGraphComponent) tabs.getSelectedComponent();
        Object c = gc.getGraph().getSelectionCell();
        mxGraph graph = gc.getGraph();
        nameTextField.setText(graph.getLabel(cell));
        nameTextField.setEditable(true);
        nameTextField.requestFocusInWindow();
        editProperty(nameTextField.getText());

    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = MSIGraphXApp.getApplication().getMainFrame();
            aboutBox = new MSIGraphXAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        MSIGraphXApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        tabs = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        openButton = new javax.swing.JButton();
        computeButton = new javax.swing.JButton();
        propertyLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        addVertexToggleButton = new javax.swing.JToggleButton();
        addEdgeToggleButton = new javax.swing.JToggleButton();
        emptyGraphButton = new javax.swing.JButton();
        selectKnownButton = new javax.swing.JToggleButton();
        selectSoughtButton = new javax.swing.JToggleButton();
        closeTabButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuOpenFile = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        buttonGroup = new javax.swing.ButtonGroup();
        buttonGroup.add(selectKnownButton);
        buttonGroup.add(selectSoughtButton);
        buttonGroup.add(addEdgeToggleButton);
        buttonGroup.add(addVertexToggleButton);

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(600, 500));

        tabs.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
        tabs.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tabs.setMinimumSize(new java.awt.Dimension(200, 100));
        tabs.setName("tabsPanel"); // NOI18N
        tabs.setPreferredSize(new java.awt.Dimension(400, 200));

        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(msigraphx.MSIGraphXApp.class).getContext().getResourceMap(MSIGraphXView.class);
        openButton.setText(resourceMap.getString("openButton.text")); // NOI18N
        openButton.setName("openButton"); // NOI18N

        computeButton.setText(resourceMap.getString("computeButton.text")); // NOI18N
        computeButton.setName("computeButton"); // NOI18N

        propertyLabel.setText(resourceMap.getString("propertyLabel.text")); // NOI18N
        propertyLabel.setName("propertyLabel"); // NOI18N

        nameTextField.setEditable(false);
        nameTextField.setText(resourceMap.getString("nameTextField.text")); // NOI18N
        nameTextField.setName("nameTextField"); // NOI18N
        nameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameTextFieldActionPerformed(evt);
            }
        });

        addVertexToggleButton.setText(resourceMap.getString("addVertexToggleButton.text")); // NOI18N
        addVertexToggleButton.setName("addVertexToggleButton"); // NOI18N
        addVertexToggleButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                addVertexToggleButtonItemStateChanged(evt);
            }
        });

        addEdgeToggleButton.setText(resourceMap.getString("addEdgeToggleButton.text")); // NOI18N
        addEdgeToggleButton.setName("addEdgeToggleButton"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(msigraphx.MSIGraphXApp.class).getContext().getActionMap(MSIGraphXView.class, this);
        emptyGraphButton.setAction(actionMap.get("addGraph")); // NOI18N
        emptyGraphButton.setText(resourceMap.getString("emptyGraphButton.text")); // NOI18N
        emptyGraphButton.setName("emptyGraphButton"); // NOI18N

        selectKnownButton.setText(resourceMap.getString("selectKnownButton.text")); // NOI18N
        selectKnownButton.setName("selectKnownButton"); // NOI18N

        selectSoughtButton.setText(resourceMap.getString("SelectSoughtButton.text")); // NOI18N
        selectSoughtButton.setName("SelectSoughtButton"); // NOI18N

        closeTabButton.setText(resourceMap.getString("closeTabButton.text")); // NOI18N
        closeTabButton.setName("closeTabButton"); // NOI18N
        closeTabButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                closeTabButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(closeTabButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(selectKnownButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(emptyGraphButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(propertyLabel, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(computeButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(nameTextField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addVertexToggleButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(addEdgeToggleButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(openButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(selectSoughtButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(emptyGraphButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(openButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(closeTabButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(selectKnownButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(selectSoughtButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(computeButton)
                .addGap(18, 18, 18)
                .addComponent(propertyLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(addVertexToggleButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(addEdgeToggleButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem2.setAction(actionMap.get("addGraph")); // NOI18N
        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        fileMenu.add(jMenuItem2);

        jMenuOpenFile.setText(resourceMap.getString("jMenuOpenFile.text")); // NOI18N
        jMenuOpenFile.setName("jMenuOpenFile"); // NOI18N
        fileMenu.add(jMenuOpenFile);

        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        fileMenu.add(jMenuItem1);

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 594, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 570, Short.MAX_VALUE)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addGap(452, 452, 452)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusMessageLabel)
                        .addComponent(statusAnimationLabel))
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTextFieldActionPerformed
        editProperty(nameTextField.getText());
        nameTextField.setEditable(false);
        nameTextField.setText("");
    }//GEN-LAST:event_nameTextFieldActionPerformed

    private void closeTabButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeTabButtonMouseClicked
        for (int i = tabs.getSelectedIndex(); i < tabs.getComponentCount() - 1; i++) {
            tabs.setTitleAt(i + 1, (((Integer) i).toString()));
        }
        tabs.remove(tabs.getSelectedComponent());
    }//GEN-LAST:event_closeTabButtonMouseClicked

    private void addVertexToggleButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_addVertexToggleButtonItemStateChanged
        nameTextField.setEditable(addVertexToggleButton.isSelected());
    }//GEN-LAST:event_addVertexToggleButtonItemStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JToggleButton addEdgeToggleButton;
    protected javax.swing.JToggleButton addVertexToggleButton;
    protected javax.swing.ButtonGroup buttonGroup;
    protected javax.swing.JButton closeTabButton;
    protected javax.swing.JButton computeButton;
    protected javax.swing.JButton emptyGraphButton;
    javax.swing.JMenuItem jMenuItem1;
    javax.swing.JMenuItem jMenuItem2;
    javax.swing.JMenuItem jMenuOpenFile;
    protected javax.swing.JPanel jPanel1;
    protected javax.swing.JPanel mainPanel;
    protected javax.swing.JMenuBar menuBar;
    protected javax.swing.JTextField nameTextField;
    protected javax.swing.JButton openButton;
    protected javax.swing.JProgressBar progressBar;
    protected javax.swing.JLabel propertyLabel;
    protected javax.swing.JToggleButton selectKnownButton;
    protected javax.swing.JToggleButton selectSoughtButton;
    javax.swing.JLabel statusAnimationLabel;
    protected javax.swing.JLabel statusMessageLabel;
    javax.swing.JPanel statusPanel;
    protected javax.swing.JTabbedPane tabs;
    // End of variables declaration//GEN-END:variables
    protected final Timer messageTimer;
    protected final Timer busyIconTimer;
    protected final Icon idleIcon;
    protected final Icon[] busyIcons = new Icon[15];
    protected int busyIconIndex = 0;
    protected JDialog aboutBox;
    protected mxCell addFirstVertexEdge;
    protected mxGraph activeGraph;
}
